<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__PUBLIC__/css/font.css">
    <link rel="stylesheet" href="__PUBLIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="id" value="{$stock.id}">

        <!--商品名称-->
        <div class="layui-form-item">
            <label for="goods_name" class="layui-form-label">
                <span class="x-red">*</span>
                商品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="goods_name" name="goods_name" required="" lay-verify="goods_name"
                       autocomplete="off" class="layui-input" value="{$stock.goods_name}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--商品图片-->
        <div class="layui-form-item" style="display: none;">
            <label for="goods_img" class="layui-form-label">
                <span class="x-red">*</span>
                商品图片
            </label>
            <div class="layui-input-inline">
                <input type="text" id="goods_img" name="goods_img"  lay-verify="goods_img"
                       autocomplete="off" class="layui-input" value="{$stock.goods_img}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->




        <!--所属分类-->
        <div class="layui-form-item">
            <label for="cate" class="layui-form-label">
                <span class="x-red">*</span>
                所属分类
            </label>
            <div class="layui-input-inline">
                <select name="cat_id" id="cate" lay-verify="cate">
                    <option value="0">无</option>
                    <foreach name="cate" item="v" key="k">
                        <option value="{$v.id}" <if condition="$v['id'] eq $stock['cat_id']"> selected </if> >{$v.delimiter}{$v.cate_name}</option>
                    </foreach>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--进货价-->
        <div class="layui-form-item">
            <label for="goods_price" class="layui-form-label">
                <span class="x-red">*</span>
                进货价
            </label>
            <div class="layui-input-inline">
                <input type="text" id="goods_price" name="goods_price" required="" lay-verify="goods_price"
                       autocomplete="off" class="layui-input" value="{$stock.goods_price}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                    元
                </span>
            </div>
        </div>
        <!--end-->

        <!--零售价-->
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                <span class="x-red">*</span>
                零售价
            </label>
            <div class="layui-input-inline">
                <input type="text" id="price" name="price" required="" lay-verify="price"
                       autocomplete="off" class="layui-input" value="{$stock.price}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                    元
                </span>
            </div>
        </div>
        <!--end-->

        <!--计量单位-->
        <div class="layui-form-item">
            <label for="unit" class="layui-form-label">
                <span class="x-red">*</span>
                计量单位
            </label>
            <div class="layui-input-inline">
                <input type="text" id="unit" name="unit" required="" lay-verify="unit"
                       autocomplete="off" class="layui-input" value="{$stock.unit}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--重量-->
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                <span class="x-red">*</span>
                重量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="weight" name="weight" required="" lay-verify="weight"
                       autocomplete="off" class="layui-input" value="{$stock.weight}" onkeyup="stockWigth()">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">kg
                </span>
            </div>
        </div>
        <!--end-->

        <!--库存-->
        <div class="layui-form-item">
            <label for="stock" class="layui-form-label">
                <span class="x-red">*</span>
                库存
            </label>
            <div class="layui-input-inline">
                <input type="hidden" name="stock_old" value="{$stock.stock}">
                <input type="text" id="stock" name="stock" required="" readonly lay-verify="stock"
                       autocomplete="off" class="layui-input" value="{$stock.stock}" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">克
                </span>
            </div>
        </div>
        <!--end-->

        <!--是否保质期-->
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                <span class="x-red"></span>
                是否保质期
            </label>
            <div class="layui-input-inline">
                <input type="checkbox" <if condition="$stock['is_bzq'] neq 1"> checked="" </if> name="is_bzq" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                    是否保质期 ON：是 OFF：否
                </span>
            </div>
        </div>
        <!--end-->
        
        <!--保质期-->
        <div class="layui-form-item bzq" <if condition="$stock['is_bzq'] eq 1"> style="display: none;" </if>>
            <label for="bzq" class="layui-form-label">
                <span class="x-red"></span>
                保质期
            </label>
            <div class="layui-input-inline">
                <input type="text" id="bzq" name="bzq"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.bzq}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--保质期类型-->
        <div class="layui-form-item bzq" <if condition="$stock['is_bzq'] eq 1"> style="display: none;" </if>>
            <label for="bzq_type" class="layui-form-label">
                <span class="x-red"></span>
                保质期类型
            </label>
            <div class="layui-input-inline">
                <select name="bzq_type">
                    <option value="1" <if condition="$stock['bzq_type'] eq 1"> selected </if> >天</option>
                    <option value="2" <if condition="$stock['bzq_type'] eq 2"> selected </if>>月</option>
                    <option value="3" <if condition="$stock['bzq_type'] eq 3"> selected </if>>年</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                    保质期类型：1天 2月 3年
                </span>
            </div>
        </div>
        <!--end-->

        <!--商品编码-->
        <div class="layui-form-item" style="display: none;">
            <label for="goods_code" class="layui-form-label">
                <span class="x-red"></span>
                商品编码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="goods_code" name="goods_code" lay-verify="goods_code"
                       autocomplete="off" class="layui-input" value="{$stock.goods_code}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--规格型号-->
        <div class="layui-form-item" style="display: none;">
            <label for="spec" class="layui-form-label">
                <span class="x-red"></span>
                规格型号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="spec" name="spec"  lay-verify="spec"
                       autocomplete="off" class="layui-input" value="{$stock.spec}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->


        <!--厂家-->
        <div class="layui-form-item">
            <label for="company" class="layui-form-label">
                <span class="x-red"></span>
                厂家
            </label>
            <div class="layui-input-inline">
                <input type="text" id="company" name="company"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.company}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--品牌-->
        <div class="layui-form-item">
            <label for="brand" class="layui-form-label">
                <span class="x-red"></span>
                品牌
            </label>
            <div class="layui-input-inline">
                <input type="text" id="brand" name="brand"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.brand}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--产地-->
        <div class="layui-form-item">
            <label for="place" class="layui-form-label">
                <span class="x-red"></span>
                产地
            </label>
            <div class="layui-input-inline">
                <input type="text" id="place" name="place"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.place}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--商品新鲜度-->
        <div class="layui-form-item">
            <label for="freshness" class="layui-form-label">
                <span class="x-red"></span>
                商品新鲜度
            </label>
            <div class="layui-input-inline">
                <input type="text" id="freshness" name="freshness"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.freshness}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--备注-->
        <div class="layui-form-item">
            <label for="remark" class="layui-form-label">
                <span class="x-red"></span>
                备注
            </label>
            <div class="layui-input-inline">
                <input type="text" id="remark" name="remark"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.remark}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <!--用户-->
        <div class="layui-form-item" style="display: none;">
            <label for="user_name" class="layui-form-label">
                <span class="x-red"></span>
                用户
            </label>
            <div class="layui-input-inline">
                <input type="text" id="user_name" name="user_name"  lay-verify=""
                       autocomplete="off" class="layui-input" value="{$stock.user_name}" disabled="disabled">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">
                </span>
            </div>
        </div>
        <!--end-->

        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                修改
            </button>
        </div>



    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            goods_name: function(value){
                if(value.length <= 0){
                    return '分类名称太短了';
                }
            },
            goods_price: [/[0-9]$/, '进货价必须为数值'],
            price: [/[0-9]$/, '零售价必须为数值'],
            // weight: [/[0-9]$/, '重量必须为数值'],
            stock: [/[0-9]$/, '库存必须为数值'],
        });

        //输入库存自动计算重量
        stockWigth = function () {
            var stock = $("input[name=weight]").val() * 1000;
            $('input[name=stock]').val(stock);
        };

        //监听是否保质期按钮
        form.on('switch(switchTest)', function(data){
            if (data.elem.checked == false) {
                $('.bzq').hide();
            } else {
                $('.bzq').show();
            }
        });  


        //监听提交
        form.on('submit(add)', function(data){
            $.post("{:U('Stock/update')}", data.field, function(resp) {
                console.log(resp);
                if (resp.code == 0) {
                    layer.alert("修改成功", {icon: 6},function () {
//                        // 获得frame索引
//                        var index = parent.layer.getFrameIndex(window.name);
//                        //关闭当前frame
//                        parent.layer.close(index);
                        parent.location.reload();
                    });
                } else {
                    layer.msg(resp.msg, function () { });
                }
            }, 'json')

            return false;
        });


    });
</script>

</body>

</html>